import {nextTick, onMounted, onUnmounted, ref} from "vue";

export function useTableHeight(el) {
    const tableContentRef = ref(null)
    const tableHeight = ref(100)
    onMounted(async ()=>{
        nextTick(() => {
            updateTableHeight()
            window.addEventListener('resize', updateTableHeight);
        })
    })
    onUnmounted(() => {
        window.removeEventListener('resize', updateTableHeight);
    })

    function updateTableHeight() {
        if (!tableContentRef.value) return;
        console.log(tableContentRef.value.clientHeight)
        tableHeight.value = Math.max(300, tableContentRef.value.clientHeight); // 保留最小高度
    }
    return {
        tableContentRef,
        tableHeight
    }
}